﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml;


namespace Recherche_Concert
{
    public class WeatherApi
    {
        #region Champs
        private static string url_getWeather = "http://api.previmeteo.com/044d8595af66ac85c2f2d20b79eee99f/ig/api?weather=#city#,FR&hl=fr";
        
        #endregion

        #region Méthodes
        public static Weather getWeather(string city,DateTime dateConcert)
        {
            string urlWeather = url_getWeather.Replace("#city#",city);
            Weather theWeather = new Weather();

            IEnumerable<XElement> xLesWeather = XDocument.Load(urlWeather).Root.Element("weather").Elements("forecast_conditions");

            foreach (XElement xWeather in xLesWeather)
            {
           
                string test1=xWeather.Element("day_of_week").Attribute("data").Value;
                string test2=Weather.getDay(dateConcert);

                if (test2.StartsWith(test1))
                {
                    Weather getTheWeather = new Weather(Weather.getDay(dateConcert).ToString(), xWeather.Element("low").Attribute("data").Value, xWeather.Element("high").Attribute("data").Value, xWeather.Element("condition").Attribute("data").Value);
                    theWeather=getTheWeather;
                }
            }
            return theWeather;
        }
        #endregion
    }
}
